//index.js
//获取应用实例
// var util = require('../../utils/util.js');
import throttle from '../../utils/throttle.js';
import { formatDistance } from '../../utils/util.js';
const app = getApp();
// 引入SDK核心类
var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
var qqmapsdk;

Page({
    data: {
        //测试点数量
        numArr: [],
        //tabbar背景
        tabbarlist: [
            {
                text: '地图',
                num: 0,
            },
            {
                text: '通答',
                num: 0,
            },
            {
                text: '经验',
                num: 0,
            },
            {
                text: '我的',
                num: 0,
            },
        ],
        tabbarActive: 0,
        // 登录弹窗
        // showLoginCover: false,
        noneInfoTip: false, //无数据提示
        showStaffOrWord: false, //内部人员、口令弹窗
        showWord: false, //内部人员、口令弹窗
        powerTipCover: false, //外部人员提示
        showModal: false, //切换后台后外部人员提示
        getuserinfoBtn: false, //获取微信信息btn
        // 口令
        copyWord: false,
        copyWordValue: '',
        wordLength: 6, //输入框个数
        isFocus: true, //聚焦
        wordValue: '', //输入的内容
        ispassword: false, //是否密文显示 true为密文， false为明文。
        btuBottom: 0,
        //操作记录轮播
        operationRecord: [],
        operationRecordNum: 0,
        //通告栏
        tipHeight: 0,
        tipTop: 0,
        tipRadius: 0,
        // 地图
        mapLongitude: 116.392593,
        mapLatitude: 40.010787,
        locationLon: '',
        locationLat: '',
        mapScale: 12,
        markers: [],
        markersInfo: [],
        markersInfoIndex: 0,
        //定位 位置
        addressTap: '定位中...',
        addressBack: '定位中...',
        // 信息图标
        navData: [
            {
                imgIcon: '../../images/homepage/ft.png',
                imgShadow: '../../images/homepage/touying_lv.png',
                title: 'FT测试',
                number: '0',
            },
            {
                imgIcon: '../../images/homepage/nfc.png',
                imgShadow: '../../images/homepage/touying_hong.png',
                title: 'NFC测试',
                number: '0',
            },
            {
                imgIcon: '../../images/homepage/huanjing.png',
                imgShadow: '../../images/homepage/touying_zi.png',
                title: '运营商',
                number: '0',
            },
            {
                imgIcon: '../../images/homepage/zhuxing.png',
                imgShadow: '../../images/homepage/touying_lan.png',
                title: '车食住行',
                number: '0',
            },
            {
                imgIcon: '../../images/homepage/jingyan.png',
                imgShadow: '../../images/homepage/touying_huang.png',
                title: '当地经验',
                number: '0',
            },
        ],
        //content移动
        changeY: 821,
        buttonOpacity: 0,
        s_height: 0,
        //发布
        publishBottom: 660,
        //地图标记点查看详情
        showInfoBox: false,
        // 秘书团
        secretaryPersonNum: 0, //秘书团打卡人数
        questionAnswerNum: 0, //秘书团问答人数
        headerImgArr: [], //秘书团成员头像
        cityNotice: '', //秘书团城市公告
        showNoticeBox: false, //重要通告弹出显示
        noticeId: '', //重要通告id
        noticeTitlt: '', //重要通告标题
        htmlContent: '<p wx:nodeid="46">asdfsadf</p>', //重要通告内容
        noticePublisInfo: '', //重要通告发布信息
        choiceMappoint: false, //显示切换地图点btn
        choiceMappointValue: '全部类型', //显示切换地图点btn
        choiceType: '00',
        showCheckInBox: false, //首页打卡提示
        checkInNum: Number, //首页城市打卡数
        checkInImage: '', //刷新通告后显示打卡提示
        unHandleCnt: 0, //未处理意见建议数量
        proposalcnt: 0, //意见弹窗
        networkspeed: '00', //车食住行网速图标
    },
    //地点页面跳转
    addressTap: function () {
        if (!app.globalData.authId) return;
        wx.navigateTo({
            url: `../citySearch/citySearch?lng=${this.data.locationLon}&lat=${this.data.locationLat}`,
        });
    },
    //搜索页面跳转
    searchTap() {
        if (!app.globalData.authId) return;
        wx.navigateTo({
            url: `../search/search`,
        });
    },
    changeNav(e) {
        if (!app.globalData.authId) return;
        let index = e.currentTarget.dataset.index;
        if (index == 4) {
            wx.navigateTo({
                url: `../localExperience/localExperience`,
            });
        } else {
            wx.navigateTo({
                url: `../homePageInfo/homePageInfo?index=${index}`,
            });
        }
    },
    // 秘书团页面
    secretaryTap(e) {
        if (!app.globalData.authId) return;
        wx.navigateTo({
            url: `../secretary/secretary`,
        });
    },
    //操作记录
    recordTap(e) {
        if (!app.globalData.authId) return;
        wx.navigateTo({
            url: `./operationRecord/operationRecord?title=历史操作记录&fromWhere=00`,
        });
    },
    // 全球排行
    rankTap(e) {
        if (!app.globalData.authId) return;
        wx.navigateTo({
            url: `ranking/ranking`,
        });
    },
    // 发布
    publishBtn(e) {
        if (!app.globalData.authId) return;
        wx.navigateTo({
            url: `../../releasePage/pages/homePageInfo/homePageInfo`,
        });
    },
    // 意见反馈
    jumpAdviceTap(e) {
        if (!app.globalData.authId) return;
        wx.navigateTo({
            url: `../../releasePage/pages/addAdvice/addAdvice`,
        });
    },
    // 查看他人主页
    jumpOthersPage(e) {
        wx.navigateTo({
            url: `/functionPage/pages/othersHomePage/othersHomePage?uid=${e.currentTarget.dataset.uid}`,
        });
    },
    // 通告查看详情
    noticeInfoTap(e) {
        if (!app.globalData.authId) return;
        wx.navigateTo({
            url: `../notice/projectNotice/projectNotice?id=${this.data.noticeId}`,
        });
        this.setData({
            showNoticeBox: false,
        });
        if (
            typeof this.getTabBar === 'function' &&
            this.getTabBar() &&
            !this.data.showCheckInBox
        ) {
            this.getTabBar().setData({
                selected: 0,
                tabbarShow: true,
            });
            this.getTabBar().refresh();
        }
    },
    // 地图点查看详情
    jumpInfoTap(e) {
        console.log(e);
        //11FT测试点 21NFC测试点 31运营商信息 41租车 42住宿 51当地经验
        if (app.globalData.authId && app.globalData.authority != '07') {
            let { dotid, mtitle } = e.currentTarget.dataset;
            if (dotid || mtitle) {
                wx.showToast({
                    title: '请到春军扫网App查看详情',
                    icon: 'none',
                    duration: 1500,
                });
                return;
            }
            let url = '';
            if (e.currentTarget.dataset.secondarytype.includes('11')) {
                url = `../homePageInfo/ftInfo/ftInfo?id=${e.currentTarget.dataset.id}`;
            } else if (e.currentTarget.dataset.secondarytype.includes('21')) {
                url = `../homePageInfo/nfcInfo/nfcInfo?id=${e.currentTarget.dataset.id}`;
            } else if (e.currentTarget.dataset.secondarytype.includes('32')) {
                url = `../homePageInfo/business-hall/business-hall?id=${e.currentTarget.dataset.id}`;
            } else if (e.currentTarget.dataset.secondarytype.includes('41')) {
                url = `../../functionPage/pages/cszxDetail/cszxDetail?id=${e.currentTarget.dataset.id}&type=01`;
            } else if (e.currentTarget.dataset.secondarytype.includes('42')) {
                url = `../../functionPage/pages/cszxDetail/cszxDetail?id=${e.currentTarget.dataset.id}&type=03`;
            } else if (e.currentTarget.dataset.secondarytype.includes('43')) {
                url = `../../functionPage/pages/cszxDetail/cszxDetail?id=${e.currentTarget.dataset.id}&type=04`;
            } else if (e.currentTarget.dataset.secondarytype.includes('44')) {
                url = `../../functionPage/pages/cszxDetail/cszxDetail?id=${e.currentTarget.dataset.id}&type=02`;
            } else if (e.currentTarget.dataset.secondarytype.includes('51')) {
                url = `../../functionPage/pages/experienceDetail/experienceDetail?id=${e.currentTarget.dataset.id}`;
            }
            wx.navigateTo({
                url: url,
            });
        } else {
            this.setData({
                showStaffOrWord: true,
            });
        }
    },
    onLoad: function (options) {
        let _that = this;
        wx.removeStorageSync('refreshMapPointId');
        wx.showLoading({
            title: '加载中...',
        });
        _that.globalPhoneInfo(); //获取手机信息
        _that.getAddressInfo(); //获取定位
        let bubbleInfo = wx.getMenuButtonBoundingClientRect(); //获取小程序气泡位置
        _that.setData({
            tipHeight: bubbleInfo.height,
            tipTop: bubbleInfo.top,
            publishBottom: 660 + _that.data.btuBottom,
        });
        // 调用子组件方法，头像
        _that.headEvent = _that.selectComponent('#headEvent');
    },
    onShow: function () {
        let _that = this;
        if (app.globalData.authId) {
            _that.getNewsNum();
        }
        if (app.globalData.indexExpRefresh) {
            _that.setData({
                changeY:
                    app.globalData.windowHeight *
                        (750 / app.globalData.windowWidth) -
                    770 -
                    _that.data.btuBottom,
                publishBottom: 660 + _that.data.btuBottom,
                showInfoBox: false,
                markers: [],
                markersInfo: [],
                markersInfoIndex: 0,
            });
            wx.removeStorageSync('refreshMapPointId');
            app.globalData.indexExpRefresh = false;
        }
        _that.setData({
            addressBack: app.globalData.addressBack,
        });
        if (app.globalData.authority == '-1') {
            _that.setData({
                showStaffOrWord: true,
            });
        }
        _that.getOperationList();
        if (app.globalData.addressBack != '定位中...') {
            _that.gitCityMarkersInfo(_that.data.choiceType);
            _that.getMapPointCnt();
            _that.getCityNoticeList();
            _that.getHomePageCityInfo();
        }
        _that.getIdentity();
    },
    onReady: function (e) {
        this.mapCtx = wx.createMapContext('map');
    },
    onHide: function (e) {
        this.setData({
            choiceMappoint: false,
        });
    },
    refresh() {},
    updateMap() {
        let _that = this;
        setTimeout(function () {
            wx.hideLoading();
        }, 1500);
    },
    //获取位置信息
    getAddressInfo: function (e) {
        // 实例化API核心类
        qqmapsdk = new QQMapWX({
            key: 'OKVBZ-THB3U-FDXVD-2Q5SD-AMMOH-EPB7D',
        });
        let _that = this;
        wx.getLocation({
            type: 'wgs84',
            success(res) {
                var latitude = res.latitude;
                var longitude = res.longitude;

                _that.setData({
                    locationLon: longitude,
                    locationLat: latitude,
                    mapLongitude: longitude,
                    mapLatitude: latitude,
                });
                app.globalData.locationLat = latitude;
                app.globalData.locationLng = longitude;
                app.globalData.cityLat = latitude;
                app.globalData.cityLng = longitude;
                _that.getLocal(latitude, longitude);
                // _that.getLocal('41.32232', '19.82517');
            },
            fail: function (res) {
                _that.setData({
                    addressTap: '获取失败',
                });
                app.globalData.addressTap = _that.data.addressTap;
            },
        });
    },
    getLocal: function (latitude, longitude) {
        let _that = this;
        wx.request({
            url: `https://apis.map.qq.com/ws/geocoder/v1?location=${latitude},${longitude}&key=OKVBZ-THB3U-FDXVD-2Q5SD-AMMOH-EPB7D&language=cn`,
            data: {},
            method: 'GET',
            success: function (res) {
                console.log(res);
                let cityInfo = res.data.result.address_component;
                if (cityInfo.nation == '中国') {
                    _that.setData({
                        addressTap: cityInfo.city.replace('市', ''),
                        addressBack: cityInfo.city.replace('市', ''),
                    });
                    app.globalData.addressTap = _that.data.addressTap;
                    app.globalData.addressBack = _that.data.addressBack;
                    app.globalData.countryTap = cityInfo.nation;
                    app.globalData.countryBack = cityInfo.nation;
                    if (cityInfo.nation == '中国') {
                        app.globalData.province = cityInfo.province;
                        app.globalData.district = cityInfo.district;
                    } else {
                        app.globalData.province = '';
                        app.globalData.district = '';
                    }
                } else {
                    wx.request({
                        url: app.globalData.rootPath + `code/getCityByEnName`,
                        method: 'GET',
                        header: {
                            'content-type': 'application/x-www-form-urlencoded',
                        },
                        data: {
                            enname:
                                cityInfo.nation +
                                ',' +
                                cityInfo.ad_level_1 +
                                ',' +
                                cityInfo.ad_level_2,
                        },
                        success: function (res) {
                            console.log(res.data);
                            if (
                                res.data &&
                                res.data.data &&
                                res.data.data.name
                            ) {
                                _that.setData({
                                    addressTap:
                                        res.data.data.name ||
                                        cityInfo.ad_level_1 ||
                                        cityInfo.ad_level_2,
                                    addressBack:
                                        res.data.data.name ||
                                        cityInfo.ad_level_1 ||
                                        cityInfo.ad_level_2,
                                });
                                app.globalData.addressTap =
                                    _that.data.addressTap;
                                app.globalData.addressBack =
                                    _that.data.addressBack;
                                app.globalData.countryTap =
                                    res.data.data.country ||
                                    cityInfo.ad_level_1 ||
                                    cityInfo.ad_level_2;
                                app.globalData.countryBack =
                                    res.data.data.country ||
                                    cityInfo.ad_level_1 ||
                                    cityInfo.ad_level_2;
                            } else {
                                wx.showModal({
                                    title: '位置获取失败',
                                    content:
                                        '当前城市暂未覆盖，请联系后台管理员',
                                    showCancel: false,
                                    success: function (res) {
                                        if (res.confirm) {
                                        }
                                    },
                                });
                            }
                        },
                    });
                }
                _that.getHomePageCityInfo();
                _that.gitCityMarkersInfo();
                _that.getMapPointCnt();
                _that.getCityNoticeList();
                _that.staffOrWord();
            },
            fail: function (e) {
                wx.showToast({
                    title: '逆地址解析失败，请确认网络状况良好',
                    icon: 'none',
                    duration: 1500,
                });
            },
        });
    },
    //内部人员、口令弹窗
    staffOrWord() {
        let _that = this;
        _that.setData({
            powerTipCover: false,
        });
        console.log(app.globalData.loginPhone);
        if (app.globalData.loginPhone) {
            if (app.globalData.powerPhone.includes(app.globalData.loginPhone)) {
                app.globalData.isPowerPhone = true;
            }
            wx.request({
                url: app.globalData.rootPath + 'code/login',
                data: {
                    phone: app.globalData.loginPhone,
                    lat: app.globalData.locationLat,
                    lng: app.globalData.locationLng,
                    city: app.globalData.addressBack,
                    country: app.globalData.countryBack,
                },
                method: 'GET',
                success: function (res) {
                    if (res.data.authId && res.data.authority != '07') {
                        app.globalData.authId = res.data.authId;
                        app.globalData.authority = res.data.authority;
                        app.globalData.realname = res.data.realname;
                        app.globalData.otherauthority = res.data.otherauthority;
                        app.globalData.realpicurl = res.data.realnapicurl;
                        app.globalData.localcityTeam = res.data.localcity;
                        app.globalData.uid = res.data.uid;
                        _that.setData({
                            showCheckInBox:
                                res.data.checkCnt == 0 || res.data.checkCnt
                                    ? res.data.localcity !=
                                      app.globalData.addressBack
                                        ? true
                                        : false
                                    : false, //首页打卡提示
                            checkInNum: res.data.checkCnt || Number, //首页城市打卡数
                            unHandleCnt:
                                res.data.authority == '00' ||
                                res.data.authority == '01'
                                    ? res.data.unHandleCnt
                                    : 0,
                        });
                        _that.getNewsNum();
                        if (
                            typeof _that.getTabBar === 'function' &&
                            _that.getTabBar()
                        ) {
                            _that.getTabBar().setData({
                                selected: 0,
                                tabbarShow: true,
                            });
                            _that.getTabBar().refresh();
                        }
                    } else {
                        _that.setData({
                            showStaffOrWord: true,
                        });
                        if (
                            typeof _that.getTabBar === 'function' &&
                            _that.getTabBar()
                        ) {
                            _that.getTabBar().setData({
                                selected: 0,
                                tabbarShow: false,
                            });
                        }
                    }
                    _that.getNoticeDetail();
                },
            });
        } else {
            _that.setData({
                showStaffOrWord: true,
            });
            if (typeof _that.getTabBar === 'function' && _that.getTabBar()) {
                _that.getTabBar().setData({
                    selected: 0,
                    tabbarShow: false,
                });
            }
        }
    },
    //登录弹窗
    hideCover(e) {
        wx.showToast({
            title: '登录后方可查看更多数据',
            icon: 'none',
            duration: 1500,
        });
        this.setData({
            showStaffOrWord: false,
            powerTipCover: true,
            showWord: false,
            wordValue: '',
        });
        if (typeof this.getTabBar === 'function' && this.getTabBar()) {
            this.getTabBar().setData({
                selected: 0,
                tabbarShow: false,
            });
        }
    },
    //口令弹窗
    wordFocus(e) {
        var _that = this;
        console.log(e.detail.value);
        var inputValue = e.detail.value;
        _that.setData({
            wordValue: inputValue,
        });
        if (e.detail.value.length > 5) {
            _that.loginWord();
        }
    },
    wordTap() {
        var _that = this;
        _that.setData({
            isFocus: true,
        });
    },
    formSubmit(e) {
        console.log(e.detail.value.password);
    },
    // 口令粘贴
    pasteBtn() {
        var _that = this;
        _that.setData({
            wordValue: _that.data.copyWordValue,
            copyWordValue: '',
        });
        _that.loginWord();
    },
    // 口令登录
    loginWord() {
        var _that = this;
        wx.request({
            url: app.globalData.rootPath + 'code/login',
            data: {
                phone: _that.data.phone,
                visitorpwd: _that.data.wordValue,
                lat: app.globalData.locationLat,
                lng: app.globalData.locationLng,
                city: app.globalData.addressBack,
                country: app.globalData.countryBack,
            },
            method: 'GET',
            success: function (res) {
                console.log(res);
                if (res.data.status == 0) {
                    _that.setData({
                        showStaffOrWord: false,
                        getuserinfoBtn: false,
                        showWord: false,
                        powerTipCover: false,
                    });
                    app.globalData.getuserinfoBtn = false;
                    if (
                        typeof _that.getTabBar === 'function' &&
                        _that.getTabBar()
                    ) {
                        _that.getTabBar().setData({
                            selected: 0,
                            tabbarShow: true,
                        });
                        _that.getTabBar().refresh();
                    }
                    app.globalData.authId = res.data.authId;
                    app.globalData.authority = res.data.authority;
                    app.globalData.realname = res.data.realname;
                    app.globalData.uid = res.data.uid;
                    setTimeout(function () {
                        wx.showLoading({
                            title: '登录中',
                        });
                        wx.hideLoading();
                    }, 100);
                    _that.headEvent.getImgInfo();
                } else {
                    wx.showToast({
                        title: res.data.errmsg,
                        icon: 'none',
                        duration: 1500,
                    });
                    if (
                        typeof _that.getTabBar === 'function' &&
                        _that.getTabBar()
                    ) {
                        _that.getTabBar().setData({
                            selected: 0,
                            tabbarShow: false,
                        });
                    }
                }
            },
            fail: function (res) {
                console.log(res);
            },
        });
    },
    // 口令返回
    backStaffbox(e) {
        var _that = this;
        _that.setData({
            showWord: false,
            wordValue: '',
        });
    },
    //重要通告弹窗
    hideNoticeCover(e) {
        this.setData({
            showNoticeBox: false,
        });
        if (
            typeof this.getTabBar === 'function' &&
            this.getTabBar() &&
            !this.data.showCheckInBox
        ) {
            this.getTabBar().setData({
                selected: 0,
                tabbarShow: true,
            });
            this.getTabBar().refresh();
        }
    },
    //关闭打卡提示
    hideChickInBox(e) {
        this.setData({
            showCheckInBox: false,
        });
        if (typeof this.getTabBar === 'function' && this.getTabBar()) {
            this.getTabBar().setData({
                selected: 0,
                tabbarShow: true,
            });
            this.getTabBar().refresh();
        }
    },
    chickInTap(e) {
        this.setData({
            showCheckInBox: false,
        });
        if (typeof this.getTabBar === 'function' && this.getTabBar()) {
            this.getTabBar().setData({
                selected: 0,
                tabbarShow: true,
            });
            this.getTabBar().refresh();
        }
        wx.navigateTo({
            url: `../checkIn/checkIn`,
        });
    },
    stopEvent(e) {
        return;
    },
    toSetting(e) {
        this.getAddressInfo();
    },
    //获取用户微信头像
    toGetuserinfo(e) {
        console.log(e);
        let _that = this;
        if (e.detail.userInfo) {
            _that.setData({
                getuserinfoBtn: false,
            });
            app.globalData.wxavatarUrl = e.detail.userInfo.avatarUrl;
            app.globalData.getuserinfoBtn = false;
            wx.request({
                url: app.globalData.rootPath + 'cjMap/bindingWeChat',
                data: {
                    authId: app.globalData.authId,
                    type: '00',
                    weixinpicurl: e.detail.userInfo.avatarUrl,
                },
                method: 'GET',
                success: function (res) {
                    console.log(res);
                    if (
                        typeof _that.getTabBar === 'function' &&
                        _that.getTabBar()
                    ) {
                        _that.getTabBar().setData({
                            selected: 0,
                            tabbarShow: true,
                        });
                        _that.getTabBar().refresh();
                    }
                    if (res.data.status == 0) {
                        wx.showToast({
                            title: '授权成功',
                            icon: 'none', //如果要纯文本，不要icon，将值设为'none'
                            duration: 1500,
                        });
                    }
                },
                fail: function (res) {
                    console.log(res);
                },
            });
        }
    },
    // 定位当前位置
    getsiteBtn: function () {
        let _that = this;
        if (app.globalData.addressTap != app.globalData.addressBack) {
            app.globalData.addressBack = app.globalData.addressTap;
            app.globalData.countryBack = app.globalData.countryTap;
            _that.getHomePageCityInfo();
            _that.getCityNoticeList();
            _that.getMapPointCnt();
            _that.getIdentity();
            //无数据点覆盖
            wx.request({
                url: app.globalData.rootPath + 'code/getMapPointDetailList',
                header: {
                    'content-type': 'application/x-www-form-urlencoded', // 默认值
                },
                data: {
                    city: app.globalData.addressBack,
                    flg: '01',
                    lng: app.globalData.locationLng,
                    lat: app.globalData.locationLat,
                    createtimeorder: 'desc',
                },
                success: function (res) {
                    let data = res.data.data;
                    if (!data.length) {
                        wx.removeStorageSync('refreshMapPointId');
                        //无数据点覆盖
                        _that.setData({
                            noneInfoTip: true,
                            markers: [],
                            markersInfo: [],
                        });
                    } else {
                        _that.setData({
                            noneInfoTip: false,
                        });
                        // 缓存判断是否要更新
                        if (
                            wx.getStorageSync('refreshMapPointId') == data[0].id
                        )
                            return;
                        wx.setStorageSync('refreshMapPointId', data[0].id);
                        _that.setData({
                            markers: [],
                            markersInfo: [],
                        });
                        ///展示时
                        for (let i = 0; i < data.length; i++) {
                            let markersArr = {
                                width: 55,
                                height: 55,
                                callout: {
                                    content: '',
                                    fontSize: 13,
                                    color: '#ffffff',
                                    bgColor: '#000000AA',
                                    padding: 8,
                                    borderRadius: 30,
                                    boxShadow: '4rpx 8rpx 16rpx 0 rgba(0)',
                                    display: 'BYCLICK',
                                    anchorY: 10,
                                },
                            };
                            let markersInfoArr = {
                                uploadImg: '../../images/homepage/ft_icon.png', //发布人头像
                                distance: 0,
                                title: '测试名称',
                                address: '测试地址',
                                description: '测试描述',
                                latitude: 39.860743,
                                longitude: 116.374719,
                                id: '',
                                secondarytype: '',
                            };
                            let secondarytype =
                                data[i].secondarytype.split(',');
                            if (secondarytype.includes('11')) {
                                markersArr.iconPath =
                                    '../../images/homepage/ft_icon.png';
                            } else if (secondarytype.includes('21')) {
                                markersArr.iconPath =
                                    '../../images/homepage/nfc_icon.png';
                            } else if (secondarytype.includes('32')) {
                                markersArr.iconPath =
                                    '../../images/homepage/sim_icon.png';
                            } else if (secondarytype.includes('41')) {
                                markersArr.iconPath =
                                    '../../images/homepage/zuche_icon.png';
                            } else if (secondarytype.includes('42')) {
                                markersArr.iconPath =
                                    '../../images/homepage/zhusu_icon.png';
                            } else if (secondarytype.includes('43')) {
                                markersArr.iconPath =
                                    '../../images/homepage/chuxing_ico.png';
                            } else if (secondarytype.includes('44')) {
                                markersArr.iconPath =
                                    '../../images/homepage/meishi_ico.png';
                            } else if (secondarytype.includes('51')) {
                                markersArr.iconPath =
                                    '../../images/homepage/jingyan_icon.png';
                            }
                            if (
                                secondarytype.includes('11') &&
                                data[i].operator
                            ) {
                                markersArr.callout.content =
                                    data[i].operator +
                                    '：' +
                                    data[i].networkscene;
                            } else if (secondarytype.includes('21')) {
                                let typeName = '';
                                if (data[i].type === '01') {
                                    typeName = '易出问题点：';
                                } else if (data[i].type === '02') {
                                    typeName = '钱包消费点：';
                                } else if (data[i].type === '01,02') {
                                    typeName = '易出问题点/钱包消费点：';
                                } else if (data[i].type === '02,01') {
                                    typeName = '钱包消费点/易出问题点：';
                                }
                                if (data[i].pointname.length > 7) {
                                    typeName =
                                        typeName +
                                        data[i].pointname.slice(0, 7) +
                                        '...';
                                } else {
                                    typeName = typeName + data[i].pointname;
                                }
                                markersArr.callout.content = typeName;
                            } else if (secondarytype.includes('41')) {
                                markersArr.callout.content = data[i].title;
                            } else if (secondarytype.includes('42')) {
                                markersArr.callout.content = data[i].acctitle;
                            } else if (secondarytype.includes('43')) {
                                markersArr.callout.content = data[i].tptitle;
                            } else if (secondarytype.includes('44')) {
                                markersArr.callout.content = data[i].ftitle;
                            } else {
                                markersArr.callout.content =
                                    data[i].networkscene ||
                                    data[i].exptitle ||
                                    data[i].operator ||
                                    '当地经验';
                            }
                            markersArr.id = i;
                            markersArr.latitude = data[i].lat;
                            markersArr.longitude = data[i].lng;
                            markersInfoArr.uploadImg = data[i].realnapicurl;
                            markersInfoArr.distance = formatDistance(
                                data[i].distance
                            );
                            if (secondarytype.includes('21')) {
                                let typeName = '';
                                if (data[i].pointname.length > 12) {
                                    typeName =
                                        typeName +
                                        data[i].pointname.slice(0, 12) +
                                        '...';
                                } else {
                                    typeName = typeName + data[i].pointname;
                                }
                                markersInfoArr.title = typeName;
                            } else if (secondarytype.includes('41')) {
                                markersInfoArr.title = data[i].title;
                            } else if (secondarytype.includes('42')) {
                                markersInfoArr.title = data[i].acctitle;
                            } else if (secondarytype.includes('43')) {
                                markersInfoArr.title = data[i].tptitle;
                            } else if (secondarytype.includes('44')) {
                                markersInfoArr.title = data[i].ftitle;
                            } else {
                                markersInfoArr.title =
                                    data[i].networkscene ||
                                    data[i].exptitle ||
                                    data[i].operator ||
                                    '当地经验';
                            }
                            markersInfoArr.address = data[i].address;
                            markersInfoArr.description =
                                data[i].scenedescription ||
                                data[i].description ||
                                data[i].content ||
                                data[i].excontent ||
                                data[i].accexcontent ||
                                data[i].fexcontent ||
                                data[i].tpexcontent ||
                                data[i].backup ||
                                '暂无';
                            markersInfoArr.uid = data[i].createuid;
                            markersInfoArr.latitude = data[i].lat;
                            markersInfoArr.longitude = data[i].lng;
                            markersInfoArr.id = data[i].id;
                            markersInfoArr.secondarytype =
                                data[i].secondarytype;
                            markersInfoArr.dotid = data[i].dotid;
                            markersInfoArr.mtitle = data[i].mtitle;
                            _that.data.markers.push(markersArr);
                            _that.data.markersInfo.push(markersInfoArr);
                        }
                        _that.setData({
                            markers: _that.data.markers,
                            markersInfo: _that.data.markersInfo,
                            choiceMappointValue: '全部类型', //显示切换地图点btn
                            choiceType: '00',
                        });
                    }
                },
            });
            // 实例化API核心类
            qqmapsdk = new QQMapWX({
                key: 'OKVBZ-THB3U-FDXVD-2Q5SD-AMMOH-EPB7D',
            });
            wx.getLocation({
                type: 'wgs84',
                success(res) {
                    console.log(res);
                    var latitude = res.latitude;
                    var longitude = res.longitude;
                    app.globalData.cityLat = latitude;
                    app.globalData.cityLng = longitude;
                    _that.setData({
                        mapLongitude: longitude,
                        mapLatitude: latitude,
                        mapScale: 11,
                        addressBack: app.globalData.addressTap,
                    });
                },
                fail: function (res) {},
            });
        }
    },

    //导航
    navigateBtn(e) {
        let _that = this;
        let path;
        let secondarytype =
            _that.data.markersInfo[
                _that.data.markersInfoIndex
            ].secondarytype.split(',');

        let { dotid, mtitle } =
            _that.data.markersInfo[_that.data.markersInfoIndex];
        if (dotid || mtitle) {
            wx.showToast({
                title: '请到春军扫网App纠错',
                icon: 'none',
                duration: 1500,
            });
            return;
        }

        if (secondarytype.includes('11')) {
            path = `/releasePage/pages/homePageInfo/homePageInfo?current=0&id=${
                _that.data.markersInfo[_that.data.markersInfoIndex].id
            }`;
        } else if (secondarytype.includes('21')) {
            path = `/releasePage/pages/homePageInfo/homePageInfo?current=2&id=${
                _that.data.markersInfo[_that.data.markersInfoIndex].id
            }`;
        } else if (secondarytype.includes('32')) {
            path = `/releasePage/pages/addBusinessHall/addBusinessHall?id=${
                _that.data.markersInfo[_that.data.markersInfoIndex].id
            }`;
        } else if (secondarytype.includes('41')) {
            path = `/releasePage/pages/addFood/addFood?type=02&cszx=01&id=${
                _that.data.markersInfo[_that.data.markersInfoIndex].id
            }`;
        } else if (secondarytype.includes('42')) {
            path = `/releasePage/pages/addFood/addFood?type=02&cszx=03&id=${
                _that.data.markersInfo[_that.data.markersInfoIndex].id
            }`;
        } else if (secondarytype.includes('43')) {
            path = `/releasePage/pages/addFood/addFood?type=02&cszx=04&id=${
                _that.data.markersInfo[_that.data.markersInfoIndex].id
            }`;
        } else if (secondarytype.includes('44')) {
            path = `/releasePage/pages/addFood/addFood?type=02&cszx=02&id=${
                _that.data.markersInfo[_that.data.markersInfoIndex].id
            }`;
        } else if (secondarytype.includes('51')) {
            path = `/releasePage/pages/addExperience/addExperience?type=02&id=${
                _that.data.markersInfo[_that.data.markersInfoIndex].id
            }&current=1`;
        }
        wx.navigateTo({
            url: path,
        });
        // wx.openLocation({
        //     //​使用微信内置地图查看位置。
        //     // latitude: e.currentTarget.dataset.lat, //要去的纬度-地址
        //     latitude:
        //         _that.data.markersInfo[_that.data.markersInfoIndex].latitude,
        //     longitude:
        //         _that.data.markersInfo[_that.data.markersInfoIndex].longitude, //要去的经度-地址
        //     name: '详细地址',
        //     address:
        //         _that.data.markersInfo[_that.data.markersInfoIndex].address,
        // });
    },

    //获取,手机型号信息  显示movable-area
    globalPhoneInfo: function () {
        //机型
        let _that = this;
        let isPhone = app.globalData.isIpx;
        if (isPhone) {
            _that.setData({
                btuBottom: 64,
            });
        }
        _that.setData({
            s_height:
                app.globalData.windowHeight *
                (750 / app.globalData.windowWidth),
            changeY:
                app.globalData.windowHeight *
                    (750 / app.globalData.windowWidth) -
                770 -
                _that.data.btuBottom,
            //  443
        });
        app.globalData.screenHeight = _that.data.s_height;
    },
    getPhoneNumber: function (e) {
        var _that = this;
        console.log(e);
        if (e.detail.errMsg == 'getPhoneNumber:ok') {
            wx.request({
                url: app.globalData.rootPath + 'code/decryptUserData',
                data: {
                    encryptData: e.detail.encryptedData,
                    sessionKey: app.globalData.session_key,
                    iv: e.detail.iv,
                },
                method: 'GET',
                success: function (res) {
                    try {
                        _that.setData({
                            phone: JSON.parse(
                                res.data.resultStr
                            ).phoneNumber.match(/\d+/)[0],
                            // phone: 18851383292,
                        });
                        wx.setStorageSync('loginPhone', _that.data.phone);
                        app.globalData.loginPhone = _that.data.phone;
                        if (
                            app.globalData.powerPhone.includes(_that.data.phone)
                        ) {
                            app.globalData.isPowerPhone = true;
                        }
                        console.log(_that.data.phone);
                        if (e.currentTarget.dataset.type != '01') {
                            wx.request({
                                url: app.globalData.rootPath + 'code/login',
                                data: {
                                    phone: _that.data.phone,
                                    wxpublicopenid: app.globalData.openidValue,
                                    weixinpicurl: app.globalData.wxavatarUrl,
                                    wxunionid: app.globalData.wxunionid || '',
                                    lat: app.globalData.locationLat,
                                    lng: app.globalData.locationLng,
                                    city: app.globalData.addressBack,
                                    country: app.globalData.countryBack,
                                },
                                method: 'GET',
                                success: function (res) {
                                    console.log(res);
                                    if (res.data.status == 0) {
                                        _that.setData({
                                            showStaffOrWord: false,
                                        });
                                        if (!app.globalData.wxunionid) {
                                            if (
                                                typeof _that.getTabBar ===
                                                    'function' &&
                                                _that.getTabBar()
                                            ) {
                                                _that.getTabBar().setData({
                                                    selected: 0,
                                                    tabbarShow: false,
                                                });
                                            }
                                            wx.showModal({
                                                title: '提示',
                                                content:
                                                    "你暂未关注'湛腾科技'公众号，将无法收到内部推送。请尽快关注！",
                                                showCancel: false,
                                                success: function (res) {
                                                    if (res.confirm) {
                                                        if (
                                                            typeof _that.getTabBar ===
                                                                'function' &&
                                                            _that.getTabBar()
                                                        ) {
                                                            _that
                                                                .getTabBar()
                                                                .setData({
                                                                    selected: 0,
                                                                    tabbarShow: true,
                                                                });
                                                        }
                                                        _that.getNoticeDetail();
                                                    }
                                                },
                                            });
                                        } else {
                                            if (
                                                typeof _that.getTabBar ===
                                                    'function' &&
                                                _that.getTabBar()
                                            ) {
                                                _that.getTabBar().setData({
                                                    selected: 0,
                                                    tabbarShow: true,
                                                });
                                                _that.getTabBar().refresh();
                                            }
                                        }
                                        app.globalData.authId = res.data.authId;
                                        app.globalData.authority =
                                            res.data.authority;
                                        app.globalData.realname =
                                            res.data.realname;
                                        app.globalData.otherauthority =
                                            res.data.otherauthority;
                                        app.globalData.realpicurl =
                                            res.data.realnapicurl;
                                        app.globalData.localcityTeam =
                                            res.data.localcity;
                                        app.globalData.uid = res.data.uid;
                                        setTimeout(function () {
                                            wx.showLoading({
                                                title: '登录中',
                                            });
                                            wx.hideLoading();
                                        }, 100);
                                        _that.headEvent.getImgInfo();
                                        _that.getNewsNum();
                                        if (res.data.user.weixinpicurl) {
                                            _that.setData({
                                                getuserinfoBtn: false,
                                            });
                                            app.globalData.getuserinfoBtn = false;
                                        } else {
                                            _that.setData({
                                                getuserinfoBtn: true,
                                            });
                                            app.globalData.getuserinfoBtn = true;
                                            if (
                                                typeof _that.getTabBar ===
                                                    'function' &&
                                                _that.getTabBar()
                                            ) {
                                                _that.getTabBar().setData({
                                                    selected: 0,
                                                    tabbarShow: false,
                                                });
                                            }
                                        }
                                        if (app.globalData.authority == '07') {
                                            _that.setData({
                                                powerTipCover: true,
                                            });
                                            wx.showModal({
                                                title: '登录失败',
                                                content: '你还没有登录权限哦',
                                                showCancel: false,
                                                success: function (res) {
                                                    if (res.confirm) {
                                                        setTimeout(function () {
                                                            if (
                                                                typeof _that.getTabBar ===
                                                                    'function' &&
                                                                _that.getTabBar()
                                                            ) {
                                                                _that
                                                                    .getTabBar()
                                                                    .setData({
                                                                        selected: 0,
                                                                        tabbarShow: false,
                                                                    });
                                                            }
                                                        }, 200);
                                                        _that.setData({
                                                            showModal: true,
                                                        });
                                                    }
                                                },
                                            });
                                        } else {
                                            _that.setData({
                                                powerTipCover: false,
                                                showCheckInBox:
                                                    res.data.checkCnt == 0 ||
                                                    res.data.checkCnt
                                                        ? res.data.localcity !=
                                                          app.globalData
                                                              .addressBack
                                                            ? true
                                                            : false
                                                        : false, //首页打卡提示
                                                checkInNum:
                                                    res.data.checkCnt || Number, //首页城市打卡数
                                                unHandleCnt:
                                                    res.data.authority ==
                                                        '00' ||
                                                    res.data.authority == '01'
                                                        ? res.data.unHandleCnt
                                                        : 0,
                                            });
                                            _that.getNoticeDetail();
                                        }
                                    } else if (res.data.status == 2) {
                                        _that.setData({
                                            showStaffOrWord: false,
                                        });
                                        wx.showToast({
                                            title: '当前城市未被收录，请联系后台添加~',
                                            icon: 'none', //如果要纯文本，不要icon，将值设为'none'
                                            duration: 2000,
                                        });
                                        _that.setTeamsite(res.data.cityInfo);
                                    } else {
                                        if (
                                            res.data.errmsg ==
                                                '口令错误或已失效' ||
                                            res.data.errmsg ==
                                                '非内部员工，请使用口令登录'
                                        ) {
                                            wx.showToast({
                                                title: '非内部员工，可尝试口令登录',
                                                icon: 'none',
                                                duration: 1500,
                                            });
                                            _that.setData({
                                                powerTipCover: true,
                                            });
                                        }
                                    }
                                },
                                fail: function (res) {
                                    console.log(res);
                                },
                            });
                        } else {
                            let value = '';
                            wx.getClipboardData({
                                success(res) {
                                    let pattern = new RegExp('[0-9]+');
                                    if (pattern.test(res.data.slice(0, 6))) {
                                        value = res.data.slice(0, 6);
                                    }
                                    console.log(value);
                                },
                                complete(res) {
                                    _that.setData({
                                        showWord: true,
                                        // copyWord: copy,
                                        copyWordValue: value,
                                    });
                                },
                            });
                        }
                    } catch (e) {
                        wx.showToast({
                            title: `${e}`,
                            icon: 'none',
                            duration: 1500,
                        });
                    }
                },
            });
        }
    },
    // 外部人员提示弹窗
    powerTip() {
        let _that = this;
        _that.setData({
            showModal: true, //切换后台后防止tabbar显示
        });
        if (
            !app.globalData.authId ||
            app.globalData.authority == '07' ||
            app.globalData.authority == '-1'
        ) {
            _that.setData({
                showStaffOrWord: true,
            });
        }
    },
    exitBtn: function (e) {
        this.setData({
            showLoginCover: false,
            loginBoxCover: true,
        });
        wx.showToast({
            title: '登录后方可查看更多数据',
            icon: 'none',
            duration: 1500,
        });
    },
    // 取消登录后覆盖层
    loginCover(e) {
        this.setData({
            showLoginCover: true,
            loginBoxCover: false,
        });
    },
    stopcovermove(e) {
        return;
    },
    getHomePageCityInfo() {
        if (app.globalData.addressBack == '定位中...') return;
        let _that = this;
        wx.request({
            url: app.globalData.rootPath + `code/getHomePageCityInfo`,
            method: 'POST',
            header: {
                'content-type': 'application/x-www-form-urlencoded', // 默认值
            },
            data: {
                country: app.globalData.countryBack,
                city: app.globalData.addressBack,
            },
            success: function (res) {
                let imgArrItem = [];
                if (res.data.secretaryList.length == 0) {
                    imgArrItem.push(
                        'https://static.map8.com/sp/20200115/0_144331337686.jpg'
                    );
                } else {
                    let imgUrl;
                    if (res.data.secretaryList.length < 3) {
                        for (
                            let i = 0;
                            i < res.data.secretaryList.length;
                            i++
                        ) {
                            imgUrl =
                                res.data.secretaryList[i].weixinpicurl ||
                                res.data.secretaryList[i].realnapicurl;
                            imgArrItem.push(imgUrl);
                        }
                    } else {
                        for (let i = 0; i < 3; i++) {
                            imgUrl =
                                res.data.secretaryList[i].weixinpicurl ||
                                res.data.secretaryList[i].realnapicurl;
                            imgArrItem.push(imgUrl);
                        }
                    }
                }
                _that.setData({
                    headerImgArr: imgArrItem,
                    secretaryPersonNum: res.data.checkinPersonNum,
                    questionAnswerNum: res.data.questionAnswerNum,
                });
                _that.headEvent.getImgInfo();
            },
        });
    },
    //获取类型数量
    getMapPointCnt: function (e) {
        if (app.globalData.addressBack == '定位中...') return;
        let _that = this;
        let country;
        if (app.globalData.countryBack == '中国') {
            if (app.globalData.addressBack == '香港') {
                country = '中国香港';
            } else if (
                app.globalData.taiwan.includes(app.globalData.addressBack)
            ) {
                country = '中国台湾';
            } else if (app.globalData.addressBack == '澳门') {
                country = '中国澳门';
            } else {
                country = '中国大陆';
            }
        } else {
            country = app.globalData.countryBack;
        }
        wx.request({
            url:
                app.globalData.rootPath +
                `code/getMapPointCnt?city=${app.globalData.addressBack}&country=${app.globalData.countryBack}&region=${country}`,
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded', // 默认值
            },
            data: {},
            success: function (res) {
                for (let i = 0; i < res.data.data.length; i++) {
                    let navDataValue = 'navData[' + i + '].number';
                    _that.setData({
                        [navDataValue]: res.data.data[i].num,
                    });
                }
            },
        });
    },
    //获取地图标记点列表信息
    gitCityMarkersInfo(type = '00') {
        let _that = this;
        if (type == '00') {
            _that.setData({
                choiceMappointValue: '全部类型', //显示切换地图点btn
                choiceType: '00',
            });
        }
        wx.request({
            url: app.globalData.rootPath + 'code/getMapPointDetailList',
            header: {
                'content-type': 'application/x-www-form-urlencoded', // 默认值
            },
            data: {
                city: app.globalData.addressBack,
                flg: '01',
                lng: _that.data.locationLon,
                lat: _that.data.locationLat,
                createtimeorder: 'desc',
                type: type != '00' ? type : '',
            },
            success: function (res) {
                let data = res.data.data;
                if (!data.length && type == '00') {
                    wx.removeStorageSync('refreshMapPointId');
                    //无数据点覆盖
                    _that.setData({
                        noneInfoTip: true,
                        markers: [],
                        markersInfo: [],
                    });
                } else {
                    _that.setData({
                        noneInfoTip: false,
                    });
                    if (!data.length) {
                        // 切换类型未空时
                        _that.setData({
                            markers: [],
                            markersInfo: [],
                            markersInfoIndex: 0,
                        });
                        return;
                    }
                    // 缓存判断是否要更新
                    if (
                        wx.getStorageSync('refreshMapPointId') == data[0].id &&
                        data.length == _that.data.markersInfo.length
                    )
                        return;
                    wx.setStorageSync('refreshMapPointId', data[0].id);
                    _that.setData({
                        mapLongitude: data[0].lng,
                        mapLatitude: data[0].lat,
                        markers: [],
                        markersInfo: [],
                        markersInfoIndex: 0,
                    });
                    ///展示时
                    for (let i = 0; i < data.length; i++) {
                        let markersArr = {
                            width: 55,
                            height: 55,
                            callout: {
                                content: '',
                                fontSize: 13,
                                color: '#ffffff',
                                bgColor: '#000000AA',
                                padding: 8,
                                borderRadius: 30,
                                boxShadow: '4rpx 8rpx 16rpx 0 rgba(0)',
                                display: 'BYCLICK',
                                anchorY: 10,
                            },
                            zIndex: 1,
                        };
                        let markersInfoArr = {
                            uploadImg: '../../images/homepage/ft_icon.png', //发布人头像
                            distance: 0,
                            title: '测试名称',
                            address: '测试地址',
                            description: '测试描述',
                            latitude: 39.860743,
                            longitude: 116.374719,
                            id: '',
                            secondarytype: '',
                            operatorsValue: [''],
                        };
                        if (i == 0) {
                            markersArr.width = 76;
                            markersArr.height = 76;
                            markersArr.zIndex = 4;
                            markersArr.callout.display = 'ALWAYS';
                        } else {
                            markersArr.width = 55;
                            markersArr.height = 55;
                            markersArr.callout.display = 'BYCLICK';
                        }
                        let secondarytype = data[i].secondarytype.split(',');
                        if (secondarytype.includes('11')) {
                            let operatorsValue = data[i].operatorpicurl
                                ? data[i].operatorpicurl.split(',')
                                : [''];
                            markersArr.iconPath =
                                '../../images/homepage/ft_icon.png';
                            markersInfoArr.operatorsValue = operatorsValue;
                        } else if (secondarytype.includes('21')) {
                            markersArr.iconPath =
                                '../../images/homepage/nfc_icon.png';
                        } else if (secondarytype.includes('32')) {
                            markersArr.iconPath =
                                '../../images/homepage/sim_icon.png';
                        } else if (secondarytype.includes('41')) {
                            markersArr.iconPath =
                                '../../images/homepage/zuche_icon.png';
                        } else if (secondarytype.includes('42')) {
                            markersArr.iconPath =
                                '../../images/homepage/zhusu_icon.png';
                        } else if (secondarytype.includes('43')) {
                            markersArr.iconPath =
                                '../../images/homepage/chuxing_ico.png';
                        } else if (secondarytype.includes('44')) {
                            markersArr.iconPath =
                                '../../images/homepage/meishi_ico.png';
                        } else if (secondarytype.includes('51')) {
                            markersArr.iconPath =
                                '../../images/homepage/jingyan_icon.png';
                        }
                        if (secondarytype.includes('11') && data[i].operator) {
                            markersArr.callout.content =
                                data[i].operator + '：' + data[i].networkscene;
                        } else if (secondarytype.includes('21')) {
                            let typeName = '';
                            if (data[i].type === '01') {
                                typeName = '易出问题点：';
                            } else if (data[i].type === '02') {
                                typeName = '钱包消费点：';
                            } else if (data[i].type === '01,02') {
                                typeName = '易出问题点/钱包消费点：';
                            } else if (data[i].type === '02,01') {
                                typeName = '钱包消费点/易出问题点：';
                            }
                            if (data[i].pointname.length > 7) {
                                typeName =
                                    typeName +
                                    data[i].pointname.slice(0, 7) +
                                    '...';
                            } else {
                                typeName = typeName + data[i].pointname;
                            }
                            markersArr.callout.content = typeName;
                        } else if (secondarytype.includes('41')) {
                            markersArr.callout.content = data[i].title;
                        } else if (secondarytype.includes('42')) {
                            markersArr.callout.content = data[i].acctitle;
                        } else if (secondarytype.includes('43')) {
                            markersArr.callout.content = data[i].tptitle;
                        } else if (secondarytype.includes('44')) {
                            markersArr.callout.content = data[i].ftitle;
                        } else {
                            markersArr.callout.content =
                                data[i].networkscene ||
                                data[i].exptitle ||
                                data[i].operator ||
                                '当地经验';
                        }
                        markersArr.id = i;
                        markersArr.latitude = data[i].lat;
                        markersArr.longitude = data[i].lng;
                        markersInfoArr.uploadImg = data[i].realnapicurl;
                        markersInfoArr.distance = formatDistance(
                            data[i].distance
                        );
                        if (secondarytype.includes('21')) {
                            let typeName = '';
                            if (data[i].pointname.length > 12) {
                                typeName =
                                    typeName +
                                    data[i].pointname.slice(0, 12) +
                                    '...';
                            } else {
                                typeName = typeName + data[i].pointname;
                            }
                            markersInfoArr.title = typeName;
                        } else if (secondarytype.includes('41')) {
                            markersInfoArr.title = data[i].title;
                        } else if (secondarytype.includes('42')) {
                            markersInfoArr.title = data[i].acctitle;
                        } else if (secondarytype.includes('43')) {
                            markersInfoArr.title = data[i].tptitle;
                        } else if (secondarytype.includes('44')) {
                            markersInfoArr.title = data[i].ftitle;
                        } else {
                            markersInfoArr.title =
                                data[i].networkscene ||
                                data[i].exptitle ||
                                data[i].operator ||
                                '当地经验';
                        }
                        markersInfoArr.address = data[i].address;
                        markersInfoArr.description =
                            data[i].scenedescription ||
                            data[i].description ||
                            data[i].content ||
                            data[i].excontent ||
                            data[i].accexcontent ||
                            data[i].fexcontent ||
                            data[i].tpexcontent ||
                            data[i].backup ||
                            '暂无';
                        markersInfoArr.uid = data[i].createuid;
                        markersInfoArr.latitude = data[i].lat;
                        markersInfoArr.longitude = data[i].lng;
                        markersInfoArr.id = data[i].id;
                        markersInfoArr.secondarytype = data[i].secondarytype;
                        markersInfoArr.dotid = data[i].dotid;
                        markersInfoArr.mtitle = data[i].mtitle;
                        _that.data.markers.push(markersArr);
                        _that.data.markersInfo.push(markersInfoArr);
                    }
                    _that.setData({
                        markers: _that.data.markers,
                        markersInfo: _that.data.markersInfo,
                    });
                }
            },
        });
    },
    //地图标记点击放大
    markertap: function (e) {
        let _that = this;
        if (_that.data.showStaffOrWord) return;
        let temp = _that.data.markers[e.markerId];
        let markersCallout = 'markers[' + temp.id + '].callout.display';
        let markersWidth = 'markers[' + temp.id + '].width';
        let markersHeight = 'markers[' + temp.id + '].height';
        let markersZindex = 'markers[' + temp.id + '].zIndex';
        _that.setData({
            showInfoBox: true,
            publishBottom: 448 + _that.data.btuBottom,
        });
        if (typeof _that.getTabBar === 'function' && _that.getTabBar()) {
            _that.getTabBar().setData({
                selected: 0,
                tabbarShow: false,
            });
        }
        let hideCallout =
            'markers[' + _that.data.markersInfoIndex + '].callout.display';
        let markersWidthSmall =
            'markers[' + _that.data.markersInfoIndex + '].width';
        let markersHeightSmall =
            'markers[' + _that.data.markersInfoIndex + '].height';
        let markersZindexSmall =
            'markers[' + _that.data.markersInfoIndex + '].zIndex';
        _that.setData({
            [hideCallout]: 'BYCLICK',
            [markersWidthSmall]: 60,
            [markersHeightSmall]: 60,
            [markersZindexSmall]: 1,
            [markersCallout]: 'ALWAYS',
            [markersWidth]: 76,
            [markersHeight]: 76,
            [markersZindex]: 4,
        });

        _that.setData({
            mapLongitude: temp.longitude,
            mapLatitude: temp.latitude,
            mapScale: 13,
            markersInfoIndex: temp.id,
        });
    },
    //显示地图标记点切换Btn
    choiceMappointBtn() {
        this.setData({
            choiceMappoint: !this.data.choiceMappoint,
        });
    },
    // 点击遮盖层隐藏地图标记点切换
    closeMappointBox() {
        this.setData({
            choiceMappoint: false,
        });
        return;
    },
    //地图标记点切换
    choiceTypeBtn(e) {
        this.setData({
            choiceType: e.currentTarget.dataset.type,
            choiceMappoint: false,
            choiceMappointValue: e.currentTarget.dataset.name,
            showInfoBox: false,
            publishBottom: 660 + this.data.btuBottom,
            changeY: this.data.s_height - 770 - this.data.btuBottom,
        });
        if (app.globalData.authId && app.globalData.authority != '07') {
            if (typeof this.getTabBar === 'function' && this.getTabBar()) {
                this.getTabBar().setData({
                    selected: 0,
                    tabbarShow: true,
                });
                this.getTabBar().refresh();
            }
        }
        this.gitCityMarkersInfo(e.currentTarget.dataset.type);
    },
    // 标记点切换
    previouBtn: throttle(
        function () {
            let _that = this;
            let index = _that.data.markersInfoIndex;
            index = index - 1;
            if (index < 0) {
                index = _that.data.markersInfo.length - 1;
            }
            _that.updatemarkers(_that.data.markersInfoIndex, index);
        },
        200,
        {
            trailing: false,
        }
    ),
    // 标记点切换
    nextBtn: throttle(
        function () {
            let _that = this;
            let index = _that.data.markersInfoIndex;
            index = index + 1;
            if (index > _that.data.markersInfo.length - 1) {
                index = 0;
            }
            _that.updatemarkers(_that.data.markersInfoIndex, index);
        },
        200,
        {
            trailing: false,
        }
    ),
    //标记点左右切换放大
    updatemarkers(oldIndex, newIndex) {
        let _that = this;
        if (!_that.data.markersInfo.length) return;
        _that.setData({
            mapScale: 12,
            showInfoBox: true,
            publishBottom: 448 + _that.data.btuBottom,
        });
        let index = newIndex;
        let temp = _that.data.markersInfo[index];
        // let markerpPointArr = _that.data.markers;
        // markerpPointArr[oldIndex].callout.display = 'BYCLICK';
        // markerpPointArr[oldIndex].width = 60;
        // markerpPointArr[oldIndex].height = 60;
        // markerpPointArr[oldIndex].zIndex = 1;
        // markerpPointArr[newIndex].callout.display = 'ALWAYS';
        // markerpPointArr[newIndex].width = 76;
        // markerpPointArr[newIndex].height = 76;
        // markerpPointArr[newIndex].zIndex = 4;
        // _that.setData({
        //     markers: markerpPointArr,
        // });
        let hideCallout = 'markers[' + oldIndex + '].callout.display';
        let markersWidthSmall = 'markers[' + oldIndex + '].width';
        let markersHeightSmall = 'markers[' + oldIndex + '].height';
        let markersZindexSmall = 'markers[' + oldIndex + '].zIndex';
        let markersCallout = 'markers[' + newIndex + '].callout.display';
        let markersWidth = 'markers[' + newIndex + '].width';
        let markersHeight = 'markers[' + newIndex + '].height';
        let markersZindex = 'markers[' + newIndex + '].zIndex';
        _that.setData({
            [hideCallout]: 'BYCLICK',
            [markersWidthSmall]: 60,
            [markersHeightSmall]: 60,
            [markersZindexSmall]: 1,
            [markersCallout]: 'ALWAYS',
            [markersWidth]: 76,
            [markersHeight]: 76,
            [markersZindex]: 4,
        });
        console.log(temp);
        // 地图标记点移动效果
        _that.mapCtx.moveToLocation({
            longitude: temp.longitude,
            latitude: temp.latitude,
        });
        _that.setData({
            mapLongitude: temp.longitude,
            mapLatitude: temp.latitude,
            markersInfoIndex: newIndex,
        });
    },
    // 关闭地图标记点详情
    closeInfoBox(e) {
        let _that = this;
        let hideCallout =
            'markers[' + _that.data.markersInfoIndex + '].callout.display';
        let markersWidthSmall =
            'markers[' + _that.data.markersInfoIndex + '].width';
        let markersHeightSmall =
            'markers[' + _that.data.markersInfoIndex + '].height';
        let markersZindexSmall =
            'markers[' + _that.data.markersInfoIndex + '].zIndex';
        _that.setData({
            [hideCallout]: 'BYCLICK',
            [markersWidthSmall]: 60,
            [markersHeightSmall]: 60,
            [markersZindexSmall]: 1,
            mapScale: 12,
            showInfoBox: false,
            publishBottom: 660 + _that.data.btuBottom,
            changeY: _that.data.s_height - 770 - _that.data.btuBottom,
        });
        if (app.globalData.authId && app.globalData.authority != '07') {
            if (typeof _that.getTabBar === 'function' && _that.getTabBar()) {
                _that.getTabBar().setData({
                    selected: 0,
                    tabbarShow: true,
                });
                _that.getTabBar().refresh();
            }
        }
    },
    //获取操作记录
    getOperationList() {
        let _that = this;
        wx.request({
            url: app.globalData.rootPath + 'code/getOperationMsgList',
            header: {
                'content-type': 'application/json',
            },
            data: {
                pageSize: 20,
                pageNo: 1,
                mode: '01',
            },
            success(res) {
                console.log(res.data.data);
                for (let i = 0; i < res.data.data.length; i++) {
                    res.data.data[i].createtime = app.timeago(
                        res.data.data[i].createtime
                    );
                }
                _that.setData({
                    operationRecord: res.data.data,
                });
            },
        });
    },
    // 获取城市公告
    getCityNoticeList() {
        let _that = this;
        wx.request({
            url: app.globalData.rootPath + 'code/getCityNoticeList',
            header: {
                'content-type': 'application/json',
            },
            data: {
                authId: app.globalData.authId,
                pageSize: 1,
                pageNo: 1,
                city: app.globalData.addressBack, //城市名称
                country: app.globalData.countryBack,
            },
            success(res) {
                console.log(res.data.data);
                if (res.data.data.length) {
                    _that.setData({
                        cityNotice: res.data.data[0].content,
                    });
                } else {
                    _that.setData({
                        cityNotice:
                            '快快发布城市通告，添加这个城市的相关数据，把这个城市的经验整理出来告诉大家吧。',
                    });
                }
            },
        });
    },
    // 获取通告
    getNoticeDetail() {
        let _that = this;
        wx.request({
            url: app.globalData.rootPath + 'cjMap/getPushProjectNoticeDetail',
            header: {
                'content-type': 'application/json',
            },
            data: {
                authId: app.globalData.authId,
            },
            success(res) {
                _that.setData({
                    checkInImage: '../../images/icon/check_img.png', //刷新通告后显示打卡提示
                });
                if (res.data.projectNotice || _that.data.showCheckInBox) {
                    if (
                        typeof _that.getTabBar === 'function' &&
                        _that.getTabBar()
                    ) {
                        _that.getTabBar().setData({
                            selected: 0,
                            tabbarShow: false,
                        });
                    }
                }
                if (res.data.projectNotice) {
                    res.data.projectNotice.createtime = app.timeago(
                        res.data.projectNotice.createtime
                    );
                    _that.setData({
                        noticeId: res.data.projectNotice.id,
                        noticeTitlt: res.data.projectNotice.title, //重要通告标题
                        noticePublisInfo:
                            res.data.projectNotice.pjteamname +
                            '·' +
                            res.data.projectNotice.createrealname +
                            '·' +
                            res.data.projectNotice.createtime, //重要通告发布信息
                        showNoticeBox: res.data.projectNotice ? true : false, //重要通告弹出显示
                        htmlContent: res.data.projectNotice.text, //重要通告内容
                    });
                }
            },
        });
    },
    // 获取团长身份
    getIdentity() {
        if (
            app.globalData.authId &&
            app.globalData.authority != '00' &&
            app.globalData.authority != '01' &&
            app.globalData.authority != '07' &&
            app.globalData.authority != '09'
        ) {
            wx.request({
                url: app.globalData.rootPath + 'cjMap/getCurrentCityPermission',
                header: {
                    'content-type': 'application/json',
                },
                data: {
                    authId: app.globalData.authId,
                    city: app.globalData.addressBack, //城市名称
                    country: app.globalData.countryBack,
                },
                success(res) {
                    console.log(res.data);
                    if (res.data.authority) {
                        app.globalData.authority = res.data.authority;
                    } else {
                        app.globalData.authority = '06';
                    }
                },
            });
        }
    },
    // 获取消息数量
    getNewsNum() {
        let _that = this;
        wx.request({
            url: app.globalData.rootPath + 'cjMap/getUnreadMsgCnt',
            header: {
                'content-type': 'application/json',
            },
            data: {
                authId: app.globalData.authId,
                mode: '01',
                city: app.globalData.addressBack,
                country: app.globalData.countryBack,
            },
            success(res) {
                console.log(res.data.data);
                app.globalData.nqModuleCount = res.data.data.nqModuleCount;
                app.globalData.exModuleCount = res.data.data.exModuleCount;
                app.globalData.mineModuleCount = res.data.data.mineModuleCount;
                let arr1 = 'tabbarlist[1].num';
                let arr2 = 'tabbarlist[2].num';
                let arr3 = 'tabbarlist[3].num';
                _that.setData({
                    [arr1]: res.data.data.nqModuleCount,
                    [arr2]: res.data.data.exModuleCount,
                    [arr3]: res.data.data.mineModuleCount,
                    operationRecordNum: res.data.data.unReadCnt,
                    proposalcnt: res.data.data.proposalcnt || 0,
                    networkspeed: res.data.data.networkspeed,
                });
                if (
                    typeof _that.getTabBar === 'function' &&
                    _that.getTabBar()
                ) {
                    _that.getTabBar().refresh();
                }
            },
        });
    },
    onTabbarChange(event) {
        this.setData({ active: event.detail });
        let url;
        if (event.detail == 0) {
            url = '/pages/index/index';
        }
        if (event.detail == 1) {
            url = '/pages/notice/notice';
        }
        if (event.detail == 2) {
            url = '/pages/experience/experience';
        }
        if (event.detail == 3) {
            url = '/pages/minePage/minePage';
        }
        wx.switchTab({
            url: url,
        });
    },

    // 定位当前位置未在数据库，切换至所属团队城市信息
    setTeamsite: function (data) {
        let _that = this;
        app.globalData.cityLat = data.lat;
        app.globalData.cityLng = data.lng;
        app.globalData.locationLat = data.lat;
        app.globalData.locationLng = data.lng;
        _that.setData({
            mapLongitude: data.lng,
            mapLatitude: data.lat,
            mapScale: 11,
            addressBack: data.name,
        });
        _that.getLocal(data.lat, data.lng);
    },
});
